package com.marvels.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.marvels.system.permission.dao.AccessBarredIpMapper;

import cn.hutool.core.util.StrUtil;

/**
 * 异步执行API
 * @author wujunfeng
 *
 */
@Component
public class AsyncExecuteApi {
	
	@Autowired
	private AccessBarredIpMapper accessBarredIpMapper;
	
	@Value("${config.properties.path}")
	private String configPropertiesPath;
	
	@Async
	public void loginTransfinite(){
		try {
			// 登录失败最大次数
			String maxNum = ServerProperties.getValue(configPropertiesPath, "common.properties", "login.fail.max.num");
			maxNum = StrUtil.nullToDefault(maxNum, "10");
			// 自动把登录失败超过最大次数的IP禁掉
			accessBarredIpMapper.insertLoginTransfinite(Integer.parseInt(maxNum));
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("=======loginTransfinite=======", e);
		}
	}
}
